package com.payment.service.impl;

import com.payment.entity.Make;
import com.payment.entity.MakeWithDoctorDto;
import com.payment.mapper.ArrangeMapper;
import com.payment.mapper.MakeMapper;
import com.payment.service.MakeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class MakeServiceImpl implements MakeService {

    @Autowired
    private  MakeMapper makeMapper;
    @Autowired
    private ArrangeMapper arrangeMapper;

    @Override
    public List<MakeWithDoctorDto> getAll() {

        List<MakeWithDoctorDto> _list =makeMapper.getAll();
        List<MakeWithDoctorDto> res = new ArrayList<>();

        if (_list!=null){
            for (MakeWithDoctorDto item : _list) {
                if (item.getIsDelActive() == 0) { // 只添加未删除的用户
                    res.add(item);
                }
            }
            return res;
        }

        return res;
    }

    @Override
    public List<MakeWithDoctorDto> getByMakeState(int state) {
        return makeMapper.getByMakeState(state);
    }

    @Override
    public int del(int id) {
        return makeMapper.del(id);
    }


    @Override
    public int add(Make entity) {
        int res = makeMapper.add(entity);

        //挂号成功后 要把就诊数量减掉
        if (res>0){
            System.out.println("走了");
           arrangeMapper.updateVisitorsNumber(entity.getDoctorId());
           return 1;
        }
        return 0;

    }
}
